package com.wh.minihelp.user.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.wh.web.util.lang.StringUtil;

/**
 * 帐号与小孩的关联关系
 * 
 * @author washheart@163.com
 */
public class FamilyAccount implements Serializable {
	public static final int//
	/**
	 * 用于判断用户在家庭类型时的初始值
	 */
	NotInit = -1,
			/**
			 * 申请者
			 */
			Auditing = 0,
			/**
			 * 旁观者
			 */
			ByStander = 1,
			/**
			 * 管理者
			 */
			Manger = 2,
			/**
			 * 创建者
			 */
			CREATOR = 3,
			/**
			 * 是否已经删除。因为用户信息不可随便删除，所以家庭和帐号的关系也不随便删除，只是以后不在显示
			 */
			Deleted = 4;
	private static final long serialVersionUID = 1L;
	/**
	 * 帐号id
	 */
	private String accountId;
	/**
	 * 家庭id
	 */
	private String familyId;
	/**
	 * 创建时间
	 */
	private Date createDate;
	/**
	 * 类型
	 */
	private int type = Auditing;
	/**
	 * 是否默认
	 */
	private boolean isDefault;

	/**
	 * 对应的家庭，无需保存的数据库
	 */
	private FamilyInfo family;

	/**
	 * 对应的用户，无需保存的数据库
	 */
	private AccountInfo account;

	public FamilyAccount() {}

	public Map<String, Object> toMap() {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("accountId", accountId);
		m.put("familyId", familyId);
		m.put("createDate", StringUtil.format(createDate));
		m.put("type", type);
		m.put("isDefault", isDefault);
		m.put("typeString", getTypeString());
		m.put("family", getFamily());
		m.put("account", getAccount().toMap());
		return m;
	}

	public FamilyAccount(AccountInfo account, FamilyInfo family) {
		this.account = account;
		this.family = family;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || !(obj instanceof FamilyAccount)) return false;
		FamilyAccount fa = (FamilyAccount) obj;
		if (this.familyId != null && !this.familyId.equals(fa.getFamilyId())) return false;
		if (this.accountId != null && !this.accountId.equals(fa.getAccountId())) return false;
		return true;
	}

	public AccountInfo getAccount() {
		return account;
	}

	public void setAccount(AccountInfo account) {
		this.account = account;
	}

	public FamilyInfo getFamily() {
		return family;
	}

	public void setFamily(FamilyInfo family) {
		this.family = family;
	}

	public String getAccountId() {
		return accountId;
	}

	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getFamilyId() {
		return familyId;
	}

	public void setFamilyId(String familyId) {
		this.familyId = familyId;
	}

	public int getType() {
		return type;
	}

	public String getTypeString() {
		if (type == ByStander) {
			return "参与者";
		} else if (type == Manger) {
			return "管理者";
		} else if (type == CREATOR) {
			return "创建者";
		} else if (type == Deleted) {
			return "被请离";
		}
		return "待批准";
	}

	public void setType(int type) {
		this.type = type;
	}

	public boolean isDefault() {
		return isDefault;
	}

	public void setDefault(boolean isDefault) {
		this.isDefault = isDefault;
	}

}